package yc.day0109.travelt.service;



import yc.day0109.lottery.service.UserMgr;
import yc.day0109.travelt.constants.TourRouteType;
import yc.day0109.travelt.dao.TourRouteDao;
import yc.day0109.travelt.po.TourRoute;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.logging.Logger;

public class TourRouteMgr {
    private Logger logger = Logger.getLogger(String.valueOf(UserMgr.class));
    public void showInfo(TourRouteDao tourRouteDao){
        System.out.println("显示旅游线路详情：");
        Map<String,Object> map = new HashMap<>();
        List<TourRoute> tourRouteList = tourRouteDao.queryTourRoute(map);
        System.out.println("旅游线路名称\t\t类型\t\t价格(元)\t\t咨询电话\t\t咨询人\t\t创建日期");
        for (TourRoute tr : tourRouteList) {
            System.out.println(tr.getTrname() + "\t\t" + TourRouteType.getTourRouteTypeByCode(tr.getTrType()).getValue()
            + "\t\t" + tr.getTrPrice() + "\t\t" + tr.getTrPhone() + "\t\t" + tr.getTrUser() + "\t\t" + tr.getCreateTime());
        }
    }
    public void addTourRouteInfo(TourRouteDao tourRouteDao,Scanner sc) {
        LocalDate date = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        TourRoute tourRoute = new TourRoute();
        System.out.print("请输入旅游路线名称：");
        tourRoute.setTrname(sc.nextLine());
        System.out.print("请输入类型：");
        String trType = sc.nextLine();
        tourRoute.setTrType(Integer.parseInt(trType));
        System.out.print("请输入价格：");
        String trPrice = sc.nextLine();
        tourRoute.setTrPrice(Integer.parseInt(trPrice));
        System.out.print("请输入咨询人：");
        tourRoute.setTrUser(sc.nextLine());
        System.out.print("请输入咨询电话：");
        tourRoute.setTrPhone(sc.nextLine());
        tourRoute.setCreateTime(date.format(formatter));
        int addRes = tourRouteDao.addTourRoute(tourRoute);
        System.out.println(addRes > 0 ? "添加成功" : "添加失败");
    }
    public void deleteTourRouteInfo(TourRouteDao tourRouteDao,Scanner sc){
        System.out.print("请输入要删除的旅游路线名称：");
        String trname = sc.nextLine();
        int delRes = tourRouteDao.deleteTourRoute(trname);
        System.out.println(delRes > 0 ? "删除成功" : "删除失败");
    }
}
